
/* GCSx
** CONFIG.H
**
** Configuration loading and saving
*/

/*****************************************************************************
** Copyright (C) 2003-2006 Janson
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
*****************************************************************************/

#ifndef __GCSx_CONFIG_H_
#define __GCSx_CONFIG_H_

extern class Config {
private:
    // String settings
    std::map<Uint16, std::string> configS;
    // Numeric settings
    std::map<Uint16, Sint32> configN;
    // Reverse shortcut key lookup
    typedef std::map<Sint32, std::vector<Uint16> > SKeyMap;
    SKeyMap configK;

    int configLoaded;
    int needsSaving;
    std::string configFile;

    void loadConfig();
    void saveConfig();
    
    void addKey(Sint32 key, Uint16 cmd);
    void delKey(Sint32 key, Uint16 cmd);
    
public:
    Config();
    ~Config();
    
    // If config needs saving, save it (called on idle/exit)
    void performSave();

    // Read a setting; never assume setting is valid! Default values are
    // provided, however. Not designed for reading shortcut keys.
    Sint32 readNum(Uint16 key);
    const std::string& readStr(Uint16 key);

    // Looks up the cmd for a shortcut key, if any
    // pos 0 returns total # of possibilities
    // pos 1+ return those possibilities
    int readShortcut(Uint16 key, Uint16 mod, int pos = 1);

    // Return the default shortcut for a command
    Sint32 readShortcut(Uint16 cmd);

    // Write a setting (doesn't cache- so don't use in a time-critical situation)
    // Strings are limited to 255 characters in length or will be ignored
    // When writing shortcut keys, writing the first (non-alternate) removes
    // all alternates.
    // Use dontSave to not write config to file yet, when updating many settings
    void write(Uint16 key, Sint32 value);
    void write(Uint16 key, const std::string& value);

    // Reset to default shortcut keys
    // These don't save the config
    void clearShortcuts();
    void defaultShortcuts();
} *config;

#endif

